Ext.ux.FieldSet = function($config) {
	var _this = this;
	var thisItems1 = [];
	var thisItems2 = [];
	//new regex
//	_this.newRegex=function($regexName,$regexText,$regex){
//		var text=$regexName+'Text';		
//		var str='Ext.apply(Ext.form.VTypes, {"'+$regexName+'":function(){ return function(v){ return new RegExp("'+$regex+'").test(v);}}(),"'+text+'":"'+$regexText+'"})';
//		eval(str);
//	}
	
	var itemsLen = $config.fieldSetItems.length;				
	if (itemsLen > 0) {
		var tempArray = [];
		var tempArrayHidden = [];
		var s =0;
		var formParam = session.get("formParam");
		for (var i = 0; i < itemsLen; i++) {
			var item = $config.fieldSetItems[i];
			if(item.allowBlank == false){
				eval("item.vtype='CheckBlankOnly'");
			}
			if(typeof(item.regexpr)!='undefined'){
				//_this.newRegex(item.regexprName,item.regexprText,item.regexpr);
				//eval('item.vtype='+'"'+item.regexprName+'"');
				eval('item.regex=/'+item.regexpr+'/');
				eval('item.regexText="'+item.regexprText+'"');
			}
			if (item.allowBlank != undefined  && !item.allowBlank) {
				eval('item.labelStyle = "color:red"');
			}
			if (item.xtype === 'hidden') {
				tempArrayHidden.push(item);
			} else if (formParam != undefined && item.xtype === 'dynamicCombo') {
				var comboxUrl = item.url;
		    	var par = formParam;
		    	var postParams = "";
		    	for(var p in par) {
		    		if(postParams != "") {
		    			postParams += "&";
		    		}
		    		postParams += p +"="+ par[p];
		    		
		    	}							
		    	if (comboxUrl.lastIndexOf("?") == -1) {
					comboxUrl += "?"+postParams
				} else {
					comboxUrl += "&"+postParams
				}				
				item.url = comboxUrl;
				tempArray.push(item);
			} else {
				tempArray.push(item);
			}
		}
		//把items作为一列
		if($config.maxCols == 1){
			thisItems1 = tempArray;
			thisItems1.push(tempArrayHidden);
		}else{
			//把items按照单双数分成两个数组分别作为左右两列，如分成多列需再加判断。（解决radio下面自动换行的问题）
			for(var k = 0; k < tempArray.length; k++ ){
				if(k % 2 == 0){
					thisItems1.push( tempArray[k] )
				}else{
					thisItems2.push( tempArray[k] )
				}
			}
			
			for(var j=0;j<tempArrayHidden.length;j++) {
				if(j % 2 == 0){
					thisItems1.push( tempArrayHidden[j] )	
				}else{
					thisItems2.push( tempArrayHidden[j] )	
				}
			}
		}
		

	}
				

	var thisConfig = {
		layout     : 'column',		
		autoScroll : false,
		border:false,
		defaults   : {
			layout       : 'form',			
			labelWidth   : $config.labelWidth,
			columnWidth  : $config.columnWidth,
			defaults     : {
				anchor   : '90%'
			}
		},
		items  : [
					{ items : [thisItems1]},
					{ items : [thisItems2]}
				]
	}
	
    var _config = $config || {};
	Ext.apply(_this, Ext.apply(thisConfig, _config));
	Ext.ux.FieldSet.superclass.constructor.call(_this);
}; 

Ext.extend(Ext.ux.FieldSet,Ext.form.FieldSet,{
})




Ext.ux.DynamicItems = Ext.extend(Ext.FormPanel, {
	
		initComponent : function() {
			var _this=this;		
			
			var  _fieldSet = {
				"columnWidth"   : "",
				"labelWidth"    : "",
				"title"         : "",
				"items"         : []
			};
			if(typeof(this.fieldSet)==='object'){
		   		_fieldSet={};
		    	_fieldSet=this.fieldSet;
			}
			   		
			var thisConfig = {
	             bodyStyle:'padding:5px 5px 0',
					frame : true,
					fileUpload:true,
					items : [
						new Ext.ux.FieldSet({
							columnWidth    : _fieldSet.columnWidth,
							labelWidth     : _fieldSet.labelWidth,
							title          : _fieldSet.title,								
	                        fieldSetItems  : _fieldSet.items
	                        ,maxCols	   : _fieldSet.maxCols
						})
					]
			};
			
			Ext.apply(this, thisConfig);
			Ext.apply(this.initialConfig, thisConfig);
			Ext.ux.DynamicItems.superclass.initComponent.apply(this, arguments);
		}
})
		
